package org.alexsotob.roo.addon.flyway;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

final class DataSourcePropertyExtractor {

	private final Properties properties;

	private static final String DRIVER_CLASS_NAME_PROPERTY_NAME = "database.driverClassName";
	private static final String URL_PROPERTY_NAME = "database.url";
	private static final String USERNAME_PROPERTY_NAME = "database.username";
	private static final String PASSWORD_PROPERTY_NAME = "database.password";

	private DataSourcePropertyExtractor(InputStream propertiesInputStream)
			throws IOException {
		this.properties = new Properties();
		this.properties.load(propertiesInputStream);
	}

	String getDriverClassName() {
		return properties.getProperty(DRIVER_CLASS_NAME_PROPERTY_NAME);
	}

	String getUrlConnection() {
		return properties.getProperty(URL_PROPERTY_NAME);
	}

	String getUsername() {
		return properties.getProperty(USERNAME_PROPERTY_NAME);
	}

	String getPassword() {
		return properties.getProperty(PASSWORD_PROPERTY_NAME);
	}

	static DataSourcePropertyExtractor getInstance(
			InputStream propertiesInputStream) throws IOException {
		return new DataSourcePropertyExtractor(propertiesInputStream);
	}

}
